package com.bwie.orders.controller;

import com.bwie.common.core.domain.Result;

import com.bwie.common.redis.service.RedisService;
import com.bwie.orders.domain.dto.OrderAddDTO;
import com.bwie.orders.service.OrderService;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

@RequestMapping("order")
@RestController
@CrossOrigin
@Log4j2
public class OrderController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Autowired
    private RedisService redisService;


    @GetMapping("getToken")
    public Result getToken(){
        String token = UUID.randomUUID().toString().replaceAll("-", "");
        redisService.setCacheObject(token,token,5L, TimeUnit.MINUTES);
        return Result.success(token);
    }


    /**
     * 添加订单
     * @param orderAddDTO
     */
    @PostMapping("OrderAdd")
    public Result makeOrder(@RequestBody OrderAddDTO orderAddDTO){
        //调用方法
         orderService.orderAdd(orderAddDTO);

        return Result.success();
    }


    /**
     * 根据用户订单查询状态
     * @return
     */
    @GetMapping("selectOrderByRedis")
    public Result selectOrderByRedis(){
        int  i = orderService.selectOrderByRedis();
        return Result.success(i);
    }






}
